using Assets.Scripts.GDK;
using SimpleJson;
using System;
using System.Collections.Generic;

namespace Brick
{
	public class GameSceneModule : gdk_base_Imodule
	{
		public Action<Action> OffAnimator;

		public void OffAnimatorAction(Action callback)
		{
			if (OffAnimator == null)
			{
				callback();
			}
			else
			{
				OffAnimator(callback);
			}
		}

		public SplitConfigItem getToolsDes(int toolsID)
		{
			GameConfigModel gameConfig = GameData.gameConfig;
			List<SplitConfigItem> daojulist = gameConfig.daojulist;
			for (int i = 0; i < daojulist.Count; i++)
			{
				SplitConfigItem splitConfigItem = daojulist[i];
				if (toolsID == splitConfigItem.ID)
				{
					return splitConfigItem;
				}
			}
			return null;
		}

		public ToolsData getToolsNum(int toolsID)
		{
			if (GameData.toolsArray == null || GameData.toolsArray == string.Empty)
			{
				return null;
			}
			List<ToolsData> list = SimpleJson.SimpleJson.DeserializeObject<List<ToolsData>>(GameData.toolsArray);
			for (int i = 0; i < list.Count; i++)
			{
				if (list[i].ID == toolsID)
				{
					return list[i];
				}
			}
			return null;
		}

		public void OnGainTools(int id, int num)
		{
			switch (id)
			{
				case 2:
					GameManager.addCoin(num);
					return;
				case 1:
					GameManager.addStar(num);
					return;
			}
			ToolsData toolsData = new ToolsData();
			toolsData.ID = id;
			toolsData.num = num;
			OnGainTools(toolsData);
		}

		public void OnGainTools(ToolsData td)
		{
			List<ToolsData> list = new List<ToolsData>();
			if (GameData.toolsArray == null || GameData.toolsArray == string.Empty)
			{
				list.Add(td);
			}
			else
			{
				bool flag = false;
				list = SimpleJson.SimpleJson.DeserializeObject<List<ToolsData>>(GameData.toolsArray);
				for (int i = 0; i < list.Count; i++)
				{
					if (list[i].ID == td.ID)
					{
						flag = true;
						list[i].num = list[i].num + td.num;
						break;
					}
				}
				if (!flag)
				{
					list.Add(td);
				}
			}
			GameData.toolsArray = SimpleJson.SimpleJson.SerializeObject(list);
		}

		public void OnUseTool(int id)
		{
			ToolsData toolsData = new ToolsData();
			toolsData.ID = id;
			toolsData.num = -1;
			OnGainTools(toolsData);
		}
	}
}

